package com.CST.controller.ys;

import com.CST.common.BaseEntity;
import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YsDepartmentControlDTO;
import com.CST.entity.ys.YsDepartmentControl;
import com.CST.service.ys.YsDepartmentControlService;
import com.CST.vo.ys.YsDepartmentControlVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author nmx
 * @since 2023-06-21
 */
@Api(tags = "预算部门对照")
@RestController
@RequestMapping("/ysDepartmentControl")
public class YsDepartmentControlController {

    private final YsDepartmentControlService service;

    public YsDepartmentControlController(YsDepartmentControlService service) {
        this.service = service;
    }

    @ApiOperation("分页查询")
    @PostMapping("/listYsDepartmentControlPage")
    public ResultObject<IPage<YsDepartmentControlVO>> listYsDepartmentControlPage(@RequestBody YsDepartmentControlDTO dto) {
        return ResultObject.success(service.listYsDepartmentControlPage(dto));
    }

    @ApiOperation("新增或编辑")
    @PostMapping("/updateYsDepartmentControl")
    public ResultObject<Boolean> updateYsDepartmentControl(@RequestBody YsDepartmentControl entity) {
        return ResultObject.success(service.saveOrUpdate(entity));
    }

    @ApiOperation("删除")
    @DeleteMapping("/removeYsDepartmentControl")
    public ResultObject<Boolean> removeYsDepartmentControl(@RequestParam Long id) {
        return ResultObject.success(service.update(Wrappers.lambdaUpdate(YsDepartmentControl.class)
                .set(BaseEntity::getDeleteFlag, Boolean.TRUE)
                .eq(BaseEntity::getId, id)));
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsDepartmentControl")
    public void exportExcelYsDepartmentControl(HttpServletResponse response,@RequestBody YsDepartmentControlDTO dto) {
        service.exportExcelYsDepartmentControl(response, dto);
    }

    @ApiOperation("导出模板")
    @PostMapping("/exportExcelYsDepartmentControlDemo")
    public void exportExcelYsDepartmentControlDemo(HttpServletResponse response) {
        service.exportExcelYsDepartmentControlDemo(response);
    }

    @ApiOperation("导入")
    @PostMapping("/importExcelYsDepartmentControl")
    public void importExcelYsDepartmentControl(MultipartFile file) throws ClassNotFoundException {
        service.importExcelYsDepartmentControl(file);
    }

}
